package DAO;

import bean.Category;

import java.util.List;

public class CategoryDao extends BaseDao {
    public List<Category> getAllCategories() {
        String sql = "SELECT id, name, description FROM category";
        return queryForList(sql, Category.class);
    }

    public Category getCategoryById(Integer id) {
        String sql = "SELECT id, name, description FROM category WHERE id = ?";
        return queryForOne(sql, Category.class, id);
    }
    
    public int addCategory(Category category) {
        String sql = "INSERT INTO category (name, description) VALUES (?, ?)";
        return update(sql, category.getName(), category.getDescription());
    }
    
    public int updateCategory(Category category) {
        String sql = "UPDATE category SET name = ?, description = ? WHERE id = ?";
        return update(sql, category.getName(), category.getDescription(), category.getId());
    }
    
    public int deleteCategory(Integer id) {
        String sql = "DELETE FROM category WHERE id = ?";
        return update(sql, id);
    }
} 